//
//  AddFirendVCOfFVQM.m
//  FVQuickMessage
//
//  Created by ZMQ on 16/8/12.
//  Copyright © 2016年 zty. All rights reserved.
//

#import "AddFirendVCOfFVQM.h"

@interface AddFirendVCOfFVQM ()<UISearchBarDelegate>

@property(nonatomic, retain) UISearchBar *searchOfAdd;
@property (nonatomic, strong) UITextField *textfieldOfSeacher;

@end

@implementation AddFirendVCOfFVQM

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.title = @"添加好友";
    
    
    //返回
    self.navigationItem.leftBarButtonItem  = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(Fanhui)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
   
    //确定
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(searchBar)];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
    
    
    
    
    self.searchOfAdd = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 64, WIDTH, 40)];
    [self.view addSubview:_searchOfAdd];
    
    self.searchOfAdd.placeholder =@"快信号/手机号";
    self.searchOfAdd.delegate = self;
    self.searchOfAdd.exclusiveTouch = YES;
    [self.searchOfAdd becomeFirstResponder];
    
    
}

-(void)Fanhui{
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
}

-(void)searchBar{
   
    
    EMError * error;
    BOOL isSuccess = [[EaseMob sharedInstance].chatManager addBuddy:_textfieldOfSeacher.text message:@"我想加您为好友" error:&error];
    
    if (isSuccess && !error) {
        NSLog(@"添加成功");
           
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"对方已添加你为好友" preferredStyle: UIAlertControllerStyleAlert];
        
        UIAlertAction *alertAction  = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            
        }];
        
        [alertController addAction:alertAction];
        
        [self presentViewController:alertController animated:YES completion:^{
            
        }];
        
        
    }
    else
    {
        NSLog(@"%@",error);
        
        
        
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"对方拒绝添加你为好友" preferredStyle: UIAlertControllerStyleAlert];
        
        UIAlertAction *alertAction  = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            
            
        }];
        
        [alertController addAction:alertAction];
        
        [self presentViewController:alertController animated:YES completion:nil];
        
    }
    
    
}



    
    



@end
